<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends SMB_Controller {
	
	public function __construct() {
		parent::__construct();
		$this->load->library('announcement');
	}
	
	public function index($offset = '0') {
		$this->_get_userinfo();
		
		$this->load->library('pagination');
		$config['base_url'] = site_url($this->userinfo['role'].'/home/index');
		$config['total_rows'] = $this->announcement->count_announcement();
		$config['per_page'] = 1; 
		$config['uri_segment'] = 4;
		$config['query_string_segment'] = 'page';
		$config['display_pages'] = FALSE;
		$config['first_link'] = FALSE;
		$config['last_link'] = FALSE;
		$offset = $this->_validate_offset($offset, $config['total_rows'], 'mahasiswa/home');
		$this->pagination->initialize($config);
		
		$this->_load_common_header();
		$this->_load_common_navigation();
		$this->_load_common_sidebar(get_user_sidebar($this->userinfo['role'], 'home'));
		$params = array(
			'announcements' => $this->announcement->get_announcement($offset, 1),
			'paging' => $this->pagination->create_links()
		);
		$this->load->view('common/announcement_view', $params);
		$this->_load_common_footer();
	}
	
	public function lists() {
		$this->_get_userinfo();
		$this->load->helper('table');
		$limit = $this->announcement->count_announcement();
		
		$this->_load_common_header();
		$this->_load_common_navigation();
		$this->_load_common_sidebar(get_user_sidebar($this->userinfo['role'], 'home'));
		$params = array(
			'announcements' => $this->announcement->get_announcement('0', $limit),
			'offset' => '0',
			'role' => $this->userinfo['role'],
			'pager' => get_pager(3) 
		);
		$this->load->view('common/announcement_list', $params);
		$this->_load_common_footer();
	}
}